<?php

namespace app\common\model\user;

use app\common\model\Model;
use traits\model\SoftDelete;

class Activity extends Model
{

    use SoftDelete;


    // 表名
    protected $name = 'user_activity';


    // 追加属性
    protected $append = [
        'status_name',
    ];

    const STATUS = [
        self::STATUS_NON_PAY => '未支付',
        self::STATUS_SUCC => '已支付',
    ];

    const STATUS_SUCC = 1;
    const STATUS_NON_PAY = 0;

    public function getStatusNameAttr($value, $data)
    {
        return self::STATUS[$data['status'] ?? self::STATUS_NON_PAY] ?? '';
    }


    public function activity()
    {
        return $this->belongsTo(\app\common\model\Activity::class, 'activity_id', 'id');
    }

    public function user()
    {
        return $this->belongsTo(\app\common\model\User::class, 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
